<?php

class IndexController extends BaseController
{
	public function Index()
	{
		echo "I'm IndexController";

	}

	function Hequan()
	{
		echo "Im Hequan RUNTIME_PATH = " . RUNTIME_PATH;
	}

	function showview()
	{
		$data = array(
				'_title'	=> 'HeQuan',
				'_body'		=> "I'm body",
		);

		Factory::getView('test', $data);
	}
	
	function smarty()
	{
		$smarty = getSmartyInstance();
		
		
		// 方法一 传值
// 		$smarty->assign('title', 'hello');
// 		$smarty->display('smarty1.tpl');

		
		// 方法二 传数组
		$smarty->caching = true;
		$row = array('1', 'haozi', 'voip');
		$smarty->assign('row', $row);
		$smarty->display('smarty2.tpl');
	}
	
	// 局部缓存
	function localcache()
	{
		$smarty = getSmartyInstance();
		$smarty->caching = true;		// 开启缓存
		$smarty->cache_lifetime = 5;	// 缓存时间.默认是3600秒
		
		// 清除缓存
// 		$smarty->clear_all_cache();		// 清除所有缓存
// 		$smarty->clear_cache('index.tpl');	// 清除index.tpl的缓存
// 		$smarty->clear_cache('index.tpl', cache_id);	// 清除指定id的缓存
		
		// insert法
// 		function insert_get_current_time(){
// 			return date("Y-m-d H:i:s");
// 		}
		
// 		$date = date("Y-m-d H:i:s");
// 		$smarty->assign('date', $date);
// 		$smarty->display("smarty3.tpl", 2);

		// 动态block法
		// 2.6.27
// 		$nowtime = microtime(true);
// 		function smarty_block_nocache($param, $content, $smarty){
// 			return $content;
// 		}
		
// 		$smarty->register_block('nocache', 'smarty_block_nocache', false);
// 		$smarty->assign('data1', $nowtime);
// 		$smarty->assign('data2', $nowtime);
// 		$smarty->display('smarty4.tpl');

		// 3.1.13
		$nowtime = microtime(true);
		function smarty_block_nocache($param, $content, $smarty){
			return $content;
		}
		
		$smarty->registerPlugin('function', 'nocache', 'smarty_block_nocache');
		$smarty->assign('data1', $nowtime);
		$smarty->assign('data2', $nowtime);
		$smarty->display('smarty5.tpl');
		
	}
	
	function db()
	{
	    $index = Factory::getModule("index");
	    $data = $index->db();
	    var_dump($data);
	}
	
	function cache()
	{
	    $data = array(
	        'hequan',
	        'hequan2',
	        'hequan3',
	    );
	    $user_id = "123456";
	    do_cache('set', 'cachekey', $user_id, $data);
	    
	    $ret = do_cache('get', 'cachekey', $user_id);
	    var_dump($ret);
	    exit;
	}
	
	function api()
	{
	    $app_api = new AppApi();
	    $msg_id = 10000;
	    $ret = $app_api->getApp($msg_id);
	    var_dump($ret);exit;
	}
}
